import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:znmm/UI/A_Common/image/cached_network_Image.dart';
import 'package:znmm/UI/ProductPages/view/product_category_view.dart';
import 'package:znmm/config/app_asset.dart';
import '../model/home_natuwe_model.dart';

class NatuweGridView extends StatefulWidget {
  const NatuweGridView({super.key});

  @override
  State<NatuweGridView> createState() => _NatuweGridViewState();
}

class _NatuweGridViewState extends State<NatuweGridView> {
  final List<HomeNatuweModel> _natuweList = [];

  @override
  void initState() {
    super.initState();

    HomeNatuweModel pmol = HomeNatuweModel();
    pmol.label = "Women";
    pmol.imageUrl = "https://www.glassesin.com/image/home/women.webp";
    _natuweList.add(pmol);

    pmol = HomeNatuweModel();
    pmol.label = "Men";
    pmol.imageUrl = "https://www.glassesin.com/image/home/men.webp";
    _natuweList.add(pmol);

    pmol = HomeNatuweModel();
    pmol.label = "Reading";
    pmol.imageUrl = "https://www.glassesin.com/image/home/reading.webp";
    _natuweList.add(pmol);

    pmol = HomeNatuweModel();
    pmol.label = "Kids";
    pmol.imageUrl = "https://www.glassesin.com/image/home/kids.webp";
    _natuweList.add(pmol);

    pmol = HomeNatuweModel();
    pmol.label = "Sunglasses";
    pmol.imageUrl = "https://www.glassesin.com/image/home/sunglasses.webp";
    _natuweList.add(pmol);

    pmol = HomeNatuweModel();
    pmol.label = "Blue Light Blocking";
    _natuweList.add(pmol);
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(10),
      child: GridView.count(
        crossAxisCount: 3,
        crossAxisSpacing: 8.0,
        mainAxisSpacing: 2,
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        children: List.generate(
          _natuweList.length,
          (index) {
            HomeNatuweModel pmol = _natuweList[index];

            return GestureDetector(
              onTap: () {
                Get.to(const ProductCategoryView());
              },
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  CircleAvatar(
                    radius: 45,
                    backgroundColor: Colors.grey[200],
                    child: pmol.imageUrl.isNotEmpty
                        ? CachedNetworkImageLoader(
                            imageUrl: pmol.imageUrl,
                          )
                        : Image.asset(
                            AppAsset.imageLogo,
                            fit: BoxFit.cover,
                          ),
                  ),
                  const SizedBox(height: 4),
                  Expanded(
                      child: Text(pmol.label,
                          textAlign: TextAlign.center,
                          style: const TextStyle(
                              fontSize: 11, fontWeight: FontWeight.normal)))
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
